home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / NOBRAIN.ASM < prev    next >
Assembly Source File  |  1989-06-07  |  7KB  |  331 lines

  1. ; Date        : 27-1-1989
  2. ; Ver        : 1.04
  3. ; Program    : Kill the Brain Virus
  4. Cseg        Segment Para Public 'MyCode'
  5.         Assume    cs:Cseg,ds:Cseg
  6.         Org    100h
  7. Start:        Mov    dx,offset CRight    ;print copyright notice
  8.         Call    DispStr
  9.         Mov    ah,19h            ;get current drive
  10.         Int    21h
  11.         Mov    Drive,al        ;save it
  12.         Call    GetDrive        ;Get drive if possible
  13.         Jc    Exit
  14.         Call    ChVirus         ;virus present?
  15.         Jc    Exit            ;exit if not
  16.         Call    FindBoot        ;Find correct boot sector
  17.         Mov    dx,offset VirusKill
  18.         Call    DispStr
  19.         Call    ReadFats        ;Read the FAT tables
  20.         Jc    Exit
  21.         Call    CheckBad
  22. Exit:        Mov    ax,4C00h
  23.         Int    21h
  24. FindBoot    Proc
  25.         Mov    dl,[si+6]
  26.         Mov    ax,18            ;9 sectors/track * 2 sides
  27.         Mov    cl,[si+8]
  28.         Mul    cl
  29.         Or    dl,dl
  30.         Jz    Fb1
  31.         Add    ax,10            ;Move to the next side
  32. Fb1:        Mov    dx,ax            ;read this sector
  33.         Mov    cx,1            ;Read one sector
  34.         Mov    bx,offset PrgEnd    ;Read it here
  35.         Mov    al,Drive        ;Get drive number
  36.         Int    25h            ;Read interrupt
  37.         Jnc    Fb2
  38.         Add    sp,2
  39.         Mov    dx,offset MesOh1
  40.         Call    DispStr
  41.         Stc
  42.         Ret
  43. Fb2:        Add    sp,2
  44.         Xor    dx,dx            ;Write at boot
  45.         Mov    cx,1            ;Write one sector
  46.         Mov    bx,offset PrgEnd    ;Write from here
  47.         Mov    al,Drive        ;Get drive number
  48.         Int    26h            ;Write interrupt
  49.         Jnc    Fb3
  50.         Add    sp,2
  51.         Mov    dx,offset MesOh2    ;Print message
  52.         Call    DispStr
  53.         Stc
  54.         Ret
  55. Fb3:        Add    sp,2
  56.         Clc
  57.         Ret
  58. FindBoot    Endp
  59. PointTo     Proc
  60.         Push    bx
  61.         Mov    dx,ax
  62.         Add    ax,ax
  63.         Add    ax,dx
  64.         Mov    dx,ax
  65.         Shr    ax,1            ;Cluster * 1.5
  66.         Mov    bx,offset PrgEnd
  67.         Add    bx,ax
  68.         Mov    ax,ds:[bx]        ;Get entry
  69.         Test    dx,1
  70.         Jnz    Point1
  71.         And    ax,0FFFh
  72.         Jmp    short Point0
  73. Point1:     Shr    ax,1
  74.         Shr    ax,1
  75.         Shr    ax,1
  76.         Shr    ax,1
  77. Point0:     Pop    bx
  78.         Ret
  79. PointTo     Endp
  80. ReadFats    Proc
  81.         Mov    bx,offset PrgEnd
  82.         Mov    al,Drive
  83.         Mov    cx,4            ;read FAT1 and FAT2
  84.         Mov    dx,1            ;FAT sectors
  85.         Int    25h            ;Read FAT tables
  86.         Jnc    Rf1
  87.         Add    sp,2
  88.         Mov    dx,offset FatError
  89.         Call    DispStr
  90.         Stc
  91.         Ret
  92. Rf1:        Add    sp,2
  93.         Clc
  94.         Ret
  95. ReadFats    Endp
  96.  
  97. CheckBad    Proc
  98.         Call    FindBad         ;Find real boot sector
  99.         Call    WriteFats
  100. Exit1:        Ret
  101. CheckBad    Endp
  102. FindBad     Proc
  103.         Mov    cx,354            ;Check 354 clusters
  104.         Mov    ax,2            ;start with cluster 2
  105.         Mov    bx,ax
  106. FM:        Call    PointTo         ;Find where it points
  107.         Cmp    ax,0FF7h        ;Is it bad?
  108.         Jz    ChkBd            ;Check if realy bad
  109. FindMore1:    Inc    bx
  110.         Mov    ax,bx
  111.         Loop    FM
  112.         Ret
  113. ChkBd:        Push    ax
  114.         Call    CheckCluster        ;bx=cluster number, try to read
  115.         Pop    ax
  116.         Jmp    short FindMore1
  117. FindBad     Endp
  118. WriteFats    Proc
  119.         Mov    bx,offset PrgEnd
  120.         Mov    al,Drive
  121.         Mov    cx,4            ;FAT1 and FAT2
  122.         Mov    dx,1            ;Start of FAT sectors
  123.         Int    26h            ;Write FAT tables
  124.         Jnc    Wf1            ;Jump if not fail
  125.         Add    sp,2
  126.         Mov    dx,offset MesOh3    ;Write error
  127.         Call    DispStr
  128.         Stc
  129.         Ret
  130. Wf1:        Add    sp,2
  131.         Clc
  132.         Ret
  133. WriteFats    Endp
  134. CheckCluster    Proc
  135.         Push    bx
  136.         Push    cx
  137.         Sub    bx,2
  138.         Sal    bx,1
  139.         Add    bx,12            ;bx=sector number
  140.         Mov    dx,bx            ;sector
  141.         Mov    cx,2            ;2 sectors
  142.         Mov    bx,offset PrgEnd+205
  143.         Mov    al,Drive
  144.         Int    25h            ;Read sectors
  145.         Jnc    QRc1
  146.         Add    sp,2
  147.         Mov    al,2            ;err 2=try more
  148.         Pop    cx
  149.         Pop    bx
  150.         Ret
  151. QRc1:        Add    sp,2
  152.         Pop    cx
  153.         Pop    bx            ;Mark cluster bx as not bad
  154.         Mov    ax,bx
  155.         Push    bx
  156.         Mov    dx,ax
  157.         Add    ax,ax
  158.         Add    ax,dx
  159.         Mov    dx,ax
  160.         Shr    ax,1            ;Cluster * 1.5
  161.         Mov    bx,offset PrgEnd
  162.         Add    bx,ax
  163.         Mov    ax,ds:[bx]        ;Get entry
  164.         Test    dx,1
  165.         Jnz    QPo1
  166.         And    ax,0F000h
  167.         Jmp    short QPo2
  168. QPo1:        And    ax,000Fh
  169. QPo2:        Mov    ds:[bx],ax        ;Write entry to FAT1
  170.         Mov    ds:[bx+1024],ax     ;Write entry to FAT2
  171.         Pop    bx
  172.         Ret
  173. CheckCluster    Endp
  174.  
  175. ChVirus     Proc
  176.         Call    ReadBoot        ;Read the boot sector
  177.         Jnc    ChVirus1
  178.         Ret
  179. ChVirus1:    Mov    si,offset PrgEnd
  180.         Mov    dx,offset MesBad    ;Assume bad news
  181.         Cmp    word ptr [si+4],1234h
  182.         Jz    InThere
  183.         Mov    dx,offset MesGood    ;Assume all OK
  184.         Mov    di,436            ;Vector of interrupt 13h
  185.         Push    es
  186.         Xor    ax,ax
  187.         Mov    es,ax
  188.         Mov    ax,es:[di+2]        ;get segment of the interrupt
  189.         Pop    es
  190.         Cmp    ax,0C800h
  191.         Jb    InThere
  192.         Mov    dx,offset MesBad1    ;active now!
  193.         Call    DispStr
  194.         Mov    bx,offset PrgEnd
  195.         Mov    ah,2            ;Read
  196.         Mov    al,1            ;1 sector
  197.         Mov    dl,Drive
  198.         Xor    dh,dh            ;head number
  199.         Xor    ch,ch            ;track number
  200.         Mov    cl,1            ;sector 1
  201.         Int    6Dh            ;Virus uses interrupt 6Dh
  202.         Mov    si,offset PrgEnd
  203.         Mov    dx,offset MesBad
  204.         Cmp    word ptr [si+4],1234h
  205.         Jz    InThere1
  206.         Mov    dx,offset MesGood
  207.         Call    DispStr
  208.         Stc                ;No need to do more.
  209.         Ret
  210. InThere:    Call    DispStr
  211.         Clc                ;Do more
  212.         Ret
  213. InThere1:    Call    DispStr         ;write bad news
  214.         Mov    dx,offset MesBad2    ;No lasting effect
  215.         Jmp    short InThere
  216. ChVirus     Endp
  217. ReadBoot    Proc
  218.         Mov    bx,offset PrgEnd    ;Put it here
  219.         Mov    al,Drive        ;Drive to use
  220.         Mov    cx,1            ;One sector
  221.         Xor    dx,dx            ;Boot sector
  222.         Int    25h            ;Read it
  223.         Jnc    P0
  224.         Add    sp,2
  225.         Mov    dx,offset MesBoot
  226.         Cmp    ah,80h            ;Time-out?
  227.         Jz    P1
  228.         Mov    dx,offset MesBoot1
  229. P1:        Call    DispStr
  230.         Stc                ;Error
  231.         Ret                ;Go
  232. P0:        Add    sp,2
  233.         Clc                ;No error
  234.         Ret                ;Go
  235. ReadBoot    Endp
  236. GetDrive    Proc
  237.         Mov    si,80h
  238.         Mov    cl,[si]         ;Get length of command tail
  239.         Xor    ch,ch
  240.         Or    cx,cx
  241.         Jnz    Lab1
  242.         Cmp    byte ptr Drive,2
  243.         Jae    DriveError1
  244.         Clc
  245.         Ret
  246. Lab1:        Add    si,cx
  247.         Inc    si
  248.         Mov    byte ptr [si],0     ;Command ends with 0
  249.         Mov    si,81h
  250.         Cld
  251. SpOut:        Lodsb
  252.         Cmp    al,32
  253.         Jz    SpOut            ;Skip blanks
  254.         Or    al,al
  255.         Jnz    Stan1
  256.         Ret
  257.  
  258. Stan1:        Lodsb
  259.         Or    al,al
  260.         Jnz    Check1
  261.         Ret
  262. Check1:     Cmp    al,':'
  263.         Jnz    Stan1
  264.         Cmp    si,84h
  265. DriveCheck:    Jb    DriveError
  266.         Mov    al,[si-2]
  267.         And    al,223            ;Convert to upper case
  268.         Cmp    al,'A'
  269.         Jb    DriveError1
  270.         Cmp    al,'B'
  271.         Ja    DriveError1
  272.         Sub    al,65            ;Convert drive to 0 or 1
  273.         Mov    Drive,al
  274.         Clc
  275.         Ret
  276. DriveError:    Mov    dx,offset Err8        ;Drive expected
  277.         Call    DispStr
  278.         Stc
  279.         Ret
  280. DriveError1:    Mov    dx,offset Err9        ;Invalid drive
  281.         Call    DispStr
  282.         Stc
  283.         Ret
  284. GetDrive    Endp
  285. DispStr     Proc
  286.         Mov    ah,9
  287.         Int    21h
  288.         Ret
  289. DispStr     Endp
  290.  
  291. CRight        db    13,10
  292.         db    'Kill the <Brain> virus Ver 1.04, 27-1-1989',13,10
  293.         db    '(C) Fragakis Stelios 1988,1989',13,10,13,10,'$'
  294.  
  295.  
  296. Err8        db    'Error 8 : Drive expected.$'
  297. Err9        db    'Error 9 : Invalid drive specified. Must be A or B.$'
  298. MesBoot     db    13,10
  299.         db    'Program execution aborted. Door open?',13,10,'$'
  300. MesBoot1    db    13,10
  301.         db    'I can not read the boot sector.',13,10
  302.         db    'Disk can not contain the virus <Brain>.',13,10,'$'
  303. FatError    db    13,10
  304.         db    'Sorry, I can not read the FAT tables.',13,10
  305.         db    'FAT corrections not written to disk.',13,10,'$'
  306. VirusKill    db    'Virus <Brain> was successfully killed.',13,10,'$'
  307. MesOh1        db    'DISK ERROR : I can not read the correct boot sector.'
  308.         db    13,10,'$'
  309. MesOh2        db    'Failed to write correct boot sector in boot area.'
  310.         db    13,10,'$'
  311. MesOh3        db    'Failed to write FAT tables. Corrections lost.'
  312.         db    13,10,'$'
  313. MesGood     db    'Good News : The disk is not <Brain> contaminated.'
  314.         db    13,10,'$'
  315. MesBad        db    'Bad News : The disk is <Brain> contaminated.'
  316.         db    13,10,'$'
  317.  
  318. MesBad1     db    '* WARNING *',13,10
  319.         db    'Virus <Brain> is active right now !',13,10,'$'
  320.  
  321. MesBad2     db    13,10
  322.         db    'Remove the disk after the virus is killed',13,10
  323.         db    'to avoid the risk of contamination.',13,10,13,10,'$'
  324.  
  325. Count        db    0            ;Count 0..58
  326. Drive        db    0            ;Current drive
  327.  
  328. PrgEnd:
  329. Cseg        Ends
  330.         End    Start
  331.